# coding: utf-8

from metrics import *
from PIL import Image
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
import argparse


#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#           CLIC, Kodak, Tecknick dataset original bpp
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#


def origin_image_bpp():
    data_folder = [
        r"D:\video-communication-dataset\图像编解码测试\CLIC\professional_valid",   # CLIC
        r"D:\video-communication-dataset\图像编解码测试\kodak\archive",             # Kodak
        r"D:\video-communication-dataset\图像编解码测试\Tecnick\TESTIMAGES\RGB\RGB_OR_1200x1200"       # Tecknick
    ]

    dataset_names = ["CLIC", "Kodak", "Tecnick"]

    xlsx_save_path = r"D:\video-communication-dataset\图像编解码测试\origin_image_bpp.xlsx"

    data = {
        i: dict() for i in dataset_names
    }

    for folder, dataset in zip(data_folder, dataset_names):
        image_names = os.listdir(folder)
        bpp_list = []
        for image_name in tqdm(image_names):
            img_path = os.path.join(folder, image_name)
            image = Image.open(img_path)
            width, height = image.size
            # bpp
            bpp_val = compute_bpp(img_path, height, width)
            bpp_list.append(bpp_val)
        data[dataset]["Image name"] = image_names
        data[dataset]["BPP"] = bpp_list
        data[dataset]["Image name"].append("average")
        data[dataset]["BPP"].append(np.array(bpp_list).mean())

    dict_to_xlsx(data, xlsx_save_path)

